# MJMCS - production configuration

Options -Indexes
DirectoryIndex index.php index.html

<IfModule mod_rewrite.c>
  RewriteEngine On

  # canonical https
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

  # the old .html addresses keep working
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^([a-z0-9-]+)\.html$ /$1.php [R=301,L]

  # dynamic sitemap and robots served at their normal addresses
  RewriteRule ^sitemap\.xml$ sitemap.php [L]
  RewriteRule ^robots\.txt$ robots.php [L]

  # extensionless URLs
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^([a-z0-9-]+)$ $1.php [L]
</IfModule>

# never serve the data store or the CLI tools
RedirectMatch 404 ^/data/
RedirectMatch 404 ^/bin/

<FilesMatch "\.(json|md|sh|log)$">
  Require all denied
</FilesMatch>

<IfModule mod_headers.c>
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css application/javascript image/svg+xml
</IfModule>

ErrorDocument 404 /404.php
